package com.neu.questionnaire_system.mapper;

import com.neu.questionnaire_system.entity.QuestionHistory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author tkj
 * @since 2022-11-13
 */
@Mapper
public interface QuestionHistoryMapper extends BaseMapper<QuestionHistory> {

    @Select("select count(*) counts,qh.answerContent ,q.questionId ,q.questionType ,q.questionText from question_history qh " +
            "left join question q " +
            "on qh.questionId = q.questionId and q.qid = #{qid}" +
            "group by qh.answerContent ;")
    List<Map<String,Object>> selectAllHistoryCountByQid(@Param("qid") String qid);

    @Select("select qh.answerContent ,q.questionId ,q.questionType ,q.questionText ,a.answerName ,a.aid from question_history qh \n" +
            "left join question q " +
            "on qh.questionId = q.questionId and q.qid = #{qid}" +
            "left join answer a " +
            "on a.aid = qh.aid ;" )
    List<Map<String,Object>> selectAllHistoryByQid(@Param("qid") String qid);
}
